package cn.caplike.demo.repository.java.concurrency.threadpool;

import java.util.concurrent.*;

/**
 * Description: <br>
 * Ref: https://blog.csdn.net/ghsau/article/details/7451464
 *
 * @author LiKe
 * @date 2020-03-15 09:16:16
 */
public class T06_Future {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> task = new FutureTask<>(() -> {
            TimeUnit.MILLISECONDS.sleep(500);
            return 1000;
        });

        new Thread(task).start();

        System.out.println(task.get());//阻塞

        ExecutorService service = Executors.newFixedThreadPool(5);
        Future<Integer> f = service.submit(() -> {
            TimeUnit.MILLISECONDS.sleep(500);
            return 1;
        });

        System.out.println(f.get());
        System.out.println(f.isDone());

        service.shutdown();
    }
}
